home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Programmer's Power Pack
/
Delphi Volume 1.iso
/
e_to_l
/
fbuilder
/
delphi
/
demos
/
extfunc.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1996-09-15
|
12KB
|
355 lines
{ FormulaBuilder }
{ YGB Software, Inc. }
{ Copyright 1995 Clayton Collie }
{ All rights reserved }
{*
* External Function Module for
* FormulaBuilder 1.00 Main Demo
* Copyright 1995 Clayton Collie
* All Rights Reserved
*}
{$F+,V-}
unit extfunc;
interface
Procedure RegisterFunctions;
Procedure UnregisterFunctions;
implementation
uses sysutils,controls,forms,messages,
dialogs,
Fbcalc,
winprocs,wintypes;
const
installed : boolean = false;
constinstalled : boolean = false;
var
fnCopy, fnRename, fnExec,
fnExecWait, fnDelete,
fnErrorMsg, fnMsgBox,
fnBeep, fnYesNo,
fnYesNoCancel, fnInputstring : integer;
(* Thanks to stidolph@magnet.com (David Stidolph) for the following *)
function FileCopy(source,dest: String): Boolean;
var
fSrc,fDst,len: Integer;
size: Longint;
buffer: packed array [0..2047] of Byte;
begin
Result := False; { Assume that it WONT work }
if source <> dest then begin
fSrc := FileOpen(source,fmOpenRead);
if fSrc >= 0 then begin
size := FileSeek(fSrc,0,2);
FileSeek(fSrc,0,0);
fDst := FileCreate(dest);
if fDst >= 0 then begin
while size > 0 do begin
len := FileRead(fSrc,buffer,sizeof(buffer));
FileWrite(fDst,buffer,len);
size := size - len;
end;
FileSetDate(fDst,FileGetDate(fSrc));
FileClose(fDst);
FileSetAttr(dest,FileGetAttr(source));
Result := True;
end;
FileClose(fSrc);
end;
end;
end;
{----------------------------------------------------
Name: WinExecAndWait function
Declaration: WinExecAndWait(Path : Pchar; Visibility : word) : word;
Unit: UtilBox
Code: S
Date: 02/05/95
Description: Execute a Windows or DOS program and wait until it
returns. In the meantime, continue to process
Window messages. ( Thanks to Lar Mader. )
-----------------------------------------------------}
function WinExecAndWait(Path : Pchar; Visibility : word) : word;
var
InstanceID : THandle;
Msg : TMSg;
begin
InstanceID := WinExec(Path,Visibility);
if InstanceID < 32 then { a value less than 32 indicates an Exec error }
WinExecAndWait := InstanceID
else
repeat
while PeekMessage(Msg,0,0,0,PM_REMOVE) do begin
if Msg.Message = WM_QUIT then
halt(Msg.wParam);
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
until GetModuleUsage(InstanceID) = 0;
end;
Procedure CopyFileProc(paramcount : byte;
Const params : TActParamList;
var RetValue : TValueRec;
var nErrorCode : integer;
exprData : longint); export;
begin
retvalue.vBoolean := FileCopy(params[0].vpString^,params[1].vpString^);
end;
Procedure RenFileProc(bParamcount : byte;
Const params : TActParamList;
var RetValue : TValueRec;
var nErrorCode : integer;
exprdata : longint); export;
begin
retvalue.vBoolean := RenameFile(params[0].vpString^,params[1].vpString^);
end;
Procedure RunFileProc(bParamcount : byte;
Const params : TActParamList;
var RetValue : TValueRec;
var nErrorCode : integer;
exprdata : longint); export;
var visibility : word;
s : string[90];
begin
if (bParamcount = 1) then
visibility := SW_MAXIMIZE
else
if params[0].vInteger < 0 then
nErrorCode := EXPR_DOMAIN_ERROR
else
begin
visibility := params[0].vInteger;
s := params[0].vpString^ + #0;
retvalue.vInteger := WinExec(@s[1],visibility);
end;
end;
Procedure ExecWaitProc(bParamcount : byte;
Const params : TActParamList;
var RetValue : TValueRec;
var nErrorCode : integer;
exprdata : longint); export;
var visibility : word;
s : string[90];
begin
if (bParamcount = 1) then
visibility := SW_MAXIMIZE
else
if params[0].vInteger < 0 then
nErrorCode := EXPR_DOMAIN_ERROR
else
begin
visibility := params[0].vInteger;
s := params[0].vpString^ + #0;
retvalue.vInteger := WinExecAndWait(@s[1],visibility);
end;
end;
{* Delete a file *}
Procedure DeleteFileProc(bParamcount : byte;
Const params : TActParamList;
var RetValue : TValueRec;
var nErrorCode : integer;
exprdata : longint); export;
begin
retvalue.vBoolean := DeleteFile(params[0].vpString^);
end;
{* Show an error message dialog box *}
Procedure DispErrorProc(paramcount : byte;
const params : TActParamList;
var retvalue : TValueRec;
var nErrorCode : integer;
exprdata : longint); export;
begin
MessageDlg(params[0].vpString^,mtError, [mbOk], 0);
end;
Procedure MessageBoxProc(paramcount : byte;
const params : TActParamList;
var retvalue : TValueRec;
var nErrorCode : integer;
exprdata : longint); export;
begin
MessageDlg(params[0].vpString^,mtInformation, [mbOk], 0);
end;
Procedure BeepProc(paramcount : byte;
const params : TActParamList;
var RetValue : TValueRec;
var nErrorCode : integer;
exprdata : longint);
begin
if paramcount = 0 then
MessageBeep(mb_iconhand)
else
MessageBeep(params[0].vInteger);
end;
procedure YesNoProc(paramcount : byte;
const Params : TActParamlist;
var Retvalue : TValueRec;
var iErrcode : integer;
exprdata : longint); export;
begin
Retvalue.vBoolean := MessageDlg(params[0].vpString^,
mtConfirmation,
[mbYes, mbNo], 0) = mrYes;
end;
procedure YesNoCancelProc(paramcount : byte;
const Params : TActParamlist;
var Retvalue : TValueRec;
var iErrcode : integer;
exprdata : longint); export;
var tmp : integer;
begin
case MessageDlg(params[0].vpString^,mtConfirmation,[mbYes,mbNo,mbCancel],0)of
mrYes : retvalue.vInteger := 1;
mrNo : retvalue.vInteger := 2;
mrCancel : retvalue.vInteger := 3;
end;
end;
procedure InputStringProc(paramcount : byte;
const Params : TActParamlist;
var Retvalue : TValueRec;
var iErrcode : integer;
exprdata : longint); export;
var tmpstr : string;
begin
tmpstr := params[2].vpString^;
if InputQuery( Params[0].vpString^, params[1].vpString^, tmpstr ) then
begin
tmpstr := tmpstr + #0;
retvalue.vpString := FBCreateString(@tmpstr[1]);
end;
end;
{* Install some standard Windows.h constants *}
Procedure RegisterConstants;
begin
if constInstalled then exit;
FBAddNumericConstant('SW_HIDE',SW_HI